<?php
/**
 * 队伍管理
 */

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\TeamRequest;
use App\Http\Requests\UserContext;
use App\Http\Services\TeamService;
use App\Http\Traits\ResponseJson;

class TeamController extends Controller
{
    use ResponseJson;

    protected $teamService;

    public function __construct(TeamService $teamService)
    {
        $this->teamService = $teamService;
    }

    /**
     * 队伍列表
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function lists(UserContext $userContext)
    {
        $data = $this->teamService->lists($userContext);
        return $this->returnJson($data);
    }

    /**
     * 创建队伍
     * @param UserContext $userContext
     * @param TeamRequest $teamRequest
     * @return \Illuminate\Http\JsonResponse
     */
    public function createTeam(UserContext $userContext, TeamRequest $teamRequest)
    {
        $data = $this->teamService->createTeam($userContext, $teamRequest);
        return $this->returnJson($data);
    }

    /**
     * 加入队伍
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function entranceTeam(UserContext $userContext)
    {
        $data = $this->teamService->entranceTeam($userContext);
        return $this->returnJson($data);
    }

    /**
     * 队伍成员列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function userLists()
    {
        $data = $this->teamService->userLists();
        return $this->returnJson($data);
    }

    /**
     * 队伍设置
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateTeam(UserContext $userContext)
    {
        $data = $this->teamService->updateTeam($userContext);
        return $this->returnJson($data);
    }

    /**
     * 队伍信息
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function teamInfo(UserContext $userContext)
    {
        $data = $this->teamService->teamInfo($userContext);
        return $this->returnJson($data);
    }

    /**
     * 移除成员
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function removeMember(UserContext $userContext)
    {
        $data = $this->teamService->removeMember($userContext);
        return $this->returnJson($data);
    }

    /**
     * 更新队员在队伍位置
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateUserPos()
    {
        $data = $this->teamService->updateUserPos();
        return $this->returnJson($data);
    }
}
